<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>设置价格</title>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
    <table>
        <center>
            <h1>设置成功，程序运行中...</h1>
            <button id="searchBtn">查看历史搜索列表</button>
            <button id="orderBtn">查看历史下单成功</button>
            <button id="backBtn" onclick="gotoIndex();">重新输入检索条件</button>
            <br/>
            <button id="pauseBtn" >停止任务</button>
            <button id="resumeBtn">启动任务</button>
            <button id="getQuartzTime">查询当前任务循环时间</button>
            <br/>
            <input id="quartzTime" type="text" placeholder="在这里输入的任务循环时间" >
            <button id="setQuartzTime">重新设定任务循环时间</button>
        </center>
    </table>
    <center>
        <div style="display: block;width: 1000px">
            <div style="display: block;width: 500px;float: left">
                <center><h3>搜索历史</h3></center>
                <ol id="searchList">
                </ol>
            </div>
            <div style="display: block;width: 500px;float: left">
            <center><h3>已下订单</h3></center>
                <ol id="orderList">
                </ol>
            </div>
        </div>
    </center>
</body>
</html>
<script type="text/javascript">

    $(function(){
        $("#searchBtn").click(function(){
            $.ajax({
                type: "GET",
                url: "/getSearchList",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    var obj2 = eval(data);
                    var str = '';
                    for (let i = 0; i < obj2.length; i++) {
                        str+='<li>' + obj2[i]["goodsName"] + ' : ' + obj2[i]["setGoodsPrice"] + '元' +'</li>';
                    }
                    $("#searchList").html(str);

                },
                error: function (data){
                }
            });
        });
        setInterval(function(){
            $.ajax({
                type: "GET",
                url: "/getSearchList",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    var obj2 = eval(data);
                    var str = '';
                    for (let i = 0; i < obj2.length; i++) {
                        str+='<li>' + obj2[i]["goodsName"] + ' : ' + obj2[i]["setGoodsPrice"] + '</li>';
                    }
                    $("#searchList").html(str);

                },
                error: function (data){
                }
            });
        },1000);

        $("#orderBtn").click(function(){
            $.ajax({
                type: "GET",
                url: "/getOrderList",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    var obj2 = eval(data);
                    var str = '';
                    for (let i = 0; i < obj2.length; i++) {
                        str+='<li>' + obj2[i]["orderNo"] + ' : ' + obj2[i]["realAmount"] + ' : ' + obj2[i]["goods"][0]["goodName"] + '</li>';
                    }
                    $("#orderList").html(str);

                },
                error: function (data){
                }
            });
        });
        setInterval(function (){
            $.ajax({
                type: "GET",
                url: "/getOrderList",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    var obj2 = eval(data);
                    var str = '';
                    for (let i = 0; i < obj2.length; i++) {
                        str+='<li>' + obj2[i]["orderNo"] + ' : ' + obj2[i]["realAmount"] + ' : ' + obj2[i]["goods"][0]["goodName"] + '</li>';
                    }
                    $("#orderList").html(str);

                },
                error: function (data){
                }
            });
        },1000);

        $("#pauseBtn").click(function(){
            $.ajax({
                type: "GET",
                url: "/pause",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    alert(data);
                },
                error: function (data){
                }
            });
        });

        $("#resumeBtn").click(function(){
            $.ajax({
                type: "GET",
                url: "/start",
                // data: null,
                // dataType: "json",
                async: true,
                success: function(data){
                    alert(data);
                },
                error: function (data){
                }
            });
        });

        $("#setQuartzTime").click(function(){
            var time = $("#quartzTime").val();
            $.ajax({
                type: "GET",
                url: "/setQuartzTime",
                data: {time:time},
                // dataType: "json",
                async: true,
                success: function(data){
                    alert(data);
                },
                error: function (data){
                }
            });
        });
    });

    $("#getQuartzTime").click(function(){
        $.ajax({
            type: "GET",
            url: "/getQuartzTime",
            // data: {time:time},
            // dataType: "json",
            async: true,
            success: function(data){
                alert(data);
            },
            error: function (data){
            }
        });
    });
    // setInterval(alert($("#text").val()),3000);
    function gotoIndex(){
        window.location.href = "/";
    }
</script>